package com.crazy.crazytransactionservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crazy.crazycommon.common.BaseResponse;
import com.crazy.crazycommon.common.ErrorCode;
import com.crazy.crazycommon.common.ResultUtils;
import com.crazy.crazycommon.exception.ThrowUtils;
import com.crazy.crazymodel.model.vo.GetTransactionVO;
import com.crazy.crazytransactionservice.dto.TransactionQueryRequest;
import com.crazy.crazymodel.model.entity.Transaction;
import com.crazy.crazytransactionservice.service.TransactionService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Date: 2024-05-16-13:42
 * @Author: Zheng Zeliang
 */
@RestController
@RequestMapping("/")
public class TransactionController {
    @Resource
    private TransactionService transactionService;
    @PostMapping("/list")
    public BaseResponse<Page<GetTransactionVO>> listTransactionVoByPage(@RequestBody TransactionQueryRequest transactionQueryRequest,
                                                                  HttpServletRequest request) {
        long current = transactionQueryRequest.getCurrent();
        long pageSize = transactionQueryRequest.getPageSize();
        // 限制爬虫
        ThrowUtils.throwIf(pageSize>20, ErrorCode.PARAMS_ERROR);
        Page<GetTransactionVO> page = transactionService.listTransactionByQueryRequest(transactionQueryRequest);
        return ResultUtils.success(page);
    }
}
